package com.yimi.yinhepda.adapter.RecycleAdapter;

import android.content.Context;
import android.view.View;

import com.yimi.yinhepda.R;
import com.pda.ym.base.CommonRecycleAdapter;
import com.pda.ym.base.CommonViewHolder;
import com.yimi.yinhepda.entity.sign_manager.JiaoJianBreakCardEntity;

import java.util.List;

/**
 * 网点交件打卡适配器
 *
 * @author 000432
 * @date 2018/6/1 0001
 */

public class JiaoJianAdapter extends CommonRecycleAdapter<JiaoJianBreakCardEntity> {

    private Context mContext;
    private CommonViewHolder.onItemCommonClickListener mCommonClickListener;

    public JiaoJianAdapter(Context context, List<JiaoJianBreakCardEntity> dataList, CommonViewHolder.onItemCommonClickListener commonClickListener) {
        super(context, dataList, R.layout.adapter_jiaojian_break_card_item);
        this.mContext = context;
        this.mCommonClickListener = commonClickListener;
    }

    @Override
    public void bindData(CommonViewHolder holder, JiaoJianBreakCardEntity data, int position) {
        holder.setText(R.id.tv_stowageNum, data.getStowageNo());
        try {
            holder.setText(R.id.tv_shiftsOrder, Integer.parseInt(data.getScheduleNo().substring(10, data.getScheduleNo().length())) + "班");
        } catch (Exception e) {
            e.printStackTrace();
            holder.setText(R.id.tv_shiftsOrder, "");
        }

        String breakDate = data.getBreakDate() == null ? "" : data.getBreakDate();
        String breakTime = data.getBreakTime() == null ? "" : data.getBreakTime();
        String arriveTime = "";
        if (data.getArriveTime() != null && !"".equals(data.getArriveTime())) {
            arriveTime = data.getArriveTime();
            holder.setText(R.id.tv_break_card_time, data.getArriveTime());
        } else {
            holder.setText(R.id.tv_break_card_time, breakDate + "\n" + breakTime);
        }
        holder.setText(R.id.tv_next_station, data.getDestDeptName());

        holder.setCommonClickListener(mCommonClickListener);
        View view = holder.getView(R.id.ll_jiaoJian_item);
        if (data.isCheck()) {
            view.setBackgroundColor(mContext.getResources().getColor(R.color.yellow));
        } else if (!"".equals(arriveTime) || !"".equals(breakTime)) {
            view.setBackgroundColor(mContext.getResources().getColor(R.color.green));
        } else {
            view.setBackgroundColor(mContext.getResources().getColor(R.color.white));
        }
    }
}
